package fr.univ.lr.icone.unit;

import java.awt.Point;

import junit.framework.TestCase;
import fr.univ.lr.icone.gui.GraphicUI;
import fr.univ.lr.icone.gui.event.Event;
import fr.univ.lr.icone.gui.event.EventType;

public class GraphicUITestCase extends TestCase {

	public void testReceiveEvent() {
		Event e = new Event(001, EventType.POSITION_CHANGED);
		Event e2 = new Event(002, EventType.OPINION_CHANGED, 3);
		Event e3 = new Event(003, EventType.POSITION_CHANGED);

		GraphicUI ui = new GraphicUI();

		ui.receiveEvent(e);
		ui.receiveEvent(e2);
		ui.receiveEvent(e3);

		assertEquals(3, ui.getEventQueue().size());
		assertEquals(e, ui.getEventQueue().poll());
		assertEquals(e2, ui.getEventQueue().poll());
		assertEquals(e3, ui.getEventQueue().poll());
	}

	public void testProcessEvent() throws Exception {
		Event e = new Event(001, EventType.ENABLED_AGENT);
		Event e2 = new Event(002, EventType.ENABLED_AGENT);
		Event e3 = new Event(001, EventType.AGENT_CREATION, new Point(8, 10));

		GraphicUI ui = new GraphicUI();
		ui.start();

		Thread.sleep(1000);

		ui.receiveEvent(e);
		ui.receiveEvent(e2);
		ui.receiveEvent(e3);

		ui.processEvent();
		ui.processEvent();
		ui.processEvent();

		assertEquals(0, ui.getEventQueue().size());
	}
}
